local dibukejiao = fk.CreateSkill{
  name = "lzsj__dibukejiao",
  tags = { "Turn" },
}

Fk:loadTranslationTable{
  ["lzsj__dibukejiao"] = "敌不可剿",
  [":lzsj__dibukejiao"] = "回合技，（仅）以你（距离1以内的角色）为目标的红色牌结算后，你可视为使用一张任意【杀】或【援护】（，若未因此造成伤害，你摸两张牌，于本回合调离且此技能于本轮失效）。",
  ["@@lzsj__dibukejiao"] = "敌不可剿<font color=red><b>改</b></font>",
  [":lzsj__dibukejiao_edit"] = "以你为目标的红色即时牌结算后，你可视为使用一张任意【杀】或【援护】。",
  ["#lzsj__dibukejiao-use"] = "敌不可剿：请选择视为使用的牌",

  ["$lzsj__dibukejiao1"] = "松花江冰封战刃，北大营空留旗号！",
  ["$lzsj__dibukejiao2"] = "沈阳枪未响，已失山河三千里！",
}

local U = require "packages/utility/utility"
local DIY = require "packages/diy_utility/diy_utility"

dibukejiao:addEffect(fk.CardUseFinished, {
  anim_type = "offensive",
  dynamic_desc = function(self, player)
    local texts = "lzsj__dibukejiao"
    if player:getMark("@@lzsj__dibukejiao") > 0 then
      texts = "lzsj__dibukejiao_edit"
    end
    return texts
  end,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(dibukejiao.name) and data.card.color == Card.Red and player:usedSkillTimes(dibukejiao.name) == 0 then
      if player:getMark("@@lzsj__dibukejiao") > 0 then
        return table.contains(data.tos, player)
      else
        local to = data.tos[1]
        if to then
          return player:compareDistance(to, 1, "<=") and data:isOnlyTarget(data.tos[1])
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local names = table.filter(Fk:getAllCardNames('bt'), function (len) return string.find(len, "support") or string.find(len, "slash") end)
    local cards = U.prepareDeriveCards(room, table.map(names, function (name) return {name, Card.NoSuit, 0} end), dibukejiao.name)
      local use = room:askToUseRealCard(player, {
        pattern = cards,
        skill_name = dibukejiao.name,
        prompt = "#lzsj__dibukejiao-use",
        extra_data = { expand_pile = cards, bypass_times = true },
        skip = true,
      })
    if use then
      event:setCostData(self, {use = use})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local use = {
      card = Fk:cloneCard(event:getCostData(self).use.card.name),
      from = event:getCostData(self).use.from,
      tos = event:getCostData(self).use.tos,
      extraUse = true,
    }
    use.card.skillName = dibukejiao.name
    player.room:useCard(use)
    if player:getMark("@@lzsj__dibukejiao") == 0 and not use.damageDealt then
      player:drawCards(2, dibukejiao.name)
      DIY.removePlayer(player, "-turn")
      player.room:invalidateSkill(player, dibukejiao.name, "-round")
    end
  end,
})


return dibukejiao